#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <vector>

using namespace std;

const int num = 10;
void SubProcessRun()
{
    while(true)
    {
        cout << "i am sub process: " << getpid() << ", ppid: " << getppid() << std::endl;
        sleep(1);
    }
}

int main()
{
    vector<int> all_child;
    for (int i = 0; i < num ;i ++)
    {
        pid_t id = fork();
        if (id == 0)
        {
            SubProcessRun();
        }
        all_child.push_back(id);
    }

    cout << "所有的子进程";
    for (auto child: all_child)
    {
        cout << child << " ";
    }
    cout << endl;

    while(true)
    {
        cout << "i am a Dad" << ", pid: " << getpid()<< endl;
        sleep(1);
    }
    return 0;
}
